$().ready(function() {

	//载入
	messageLoad();

	//留言
	$("#messageLeave").click(function()
	{
		if($('#realname').attr("value")=="")
		{
			alert('名字没写吧');
		}else
		{
			messagePost();
		}
	});

});//Ready Func End

<?
/*
 * event: show control panel
 * 显示控制面板
 */
?>
function controlShow(mid)
{
	if($("#controlPanel"+mid).css("display") == "none")
	{
		$("#controlPanel"+mid).css("display","block");
	}else
	{
		$("#controlPanel"+mid).css("display","none");
	}	
}

<?
/*
 * event: hotkey
 * 热键
 */
?>
function iKeyPress(e)
{
	var isie = (document.all) ? true : false;
	var key;
	if (isie)
	{
		key = window.event.keyCode;
	}else
	{
		key = e.which;
	}
	if(13==key)
	{
		searchDesigner();
	}
}

<?
/*
 * event: load message
 * 载入留言
 */
?>
function messageLoad()
{
	//$("#messageView").load("<? //echo url('leavemessage/message'); ?>");
	$.ajax(
	{
		type: "GET",
		url: "<? echo url('leavemessage/message'); ?>",
		success: function(data)
		{
			$("#messageView").html(data);
		}
	});
}

<?
/*
 * event: post msg to the controller & then call to messageAppend()
 * 留言
 */
?>
function messagePost()
{
	var realname = $('#realname').attr("value");
	var email = $('#email').attr("value");
	var tel = $('#tel').attr("value");
	var subject = $('#subject').attr("value");
	var messageBefore = $('#messageContent').attr("value");
	message = encodeURIComponent(messageBefore);
	$.ajax(
	{
		type: "POST",
		url: "<?=url('leaveMessage/messageSet')?>",
		data: "realname="+realname+"&email="+email+"&tel="+tel+"&subject="+subject+"&message="+message,
		success: function(data)
		{
			//messageAppend(data,realname,email,tel,subject,messageBefore);
			messageLoad();
			//alert("SUCCESS!");
			inputClear();
		}
	});
}

<?
/*
 * event: append msg to the view & then call to inputClear()//***
 * 
 */
?>
function messageAppend(data,realname,email,tel,subject,message)
{
	if(0!=data)
	{
		$("#messageView").prepend('<li>'+
			'<span><a href="javascript:void(0);">'+realname+'</a>发表于：刚才'+
			'</span>'+
			'<span ><a href="javascript:void(0);" >回复</a></span>'+
			'<span ><a href="javascript:void(0);" >删除</a></span>'+
			'<br/>'+
			'<span>'+subject+'</span>'+
			'<br/>'+
			'<span>'+message+'</span>'+
			'<br/><br/>'+
			'<hr width="50%" align="left"/>'+
			'</li>');
		inputClear();
	}	
}

<?
/*
 * event: clear input
 * 清input
 */
?>
function inputClear()
{
	$('#realname').attr("value","");
	$('#email').attr("value","");
	$('#tel').attr("value","");
	$('#subject').attr("value","");
	$('#messageContent').attr("value","");
}

<?
/*
 * event: delete message & then call to messageRemove()
 * 删留言
 */
?>
function messageDelete(mid)
{
	var rs = confirm("确认要删除吗？");
	if(rs==true)
	{
		$.ajax(
		{
			type: "GET",
			url: "<? echo url('leaveMessage/MessageDelete'); ?>",
			data: "messageId="+mid,
			success: function(data)
			{
				//messageRemove();
				messageLoad();
			},
			error: function()
			{
				alert("ERROR OCCUR!");
			} 
		});
	}else
	{
		alert("好，不删了");
	}
}

<?
/*
 * event: remove message//***
 * 
 */
?>
function messageRemove()
{

}

<?
/*
 * event: change status
 * 修改状态
 */
?>
function statusChange(mid)
{
	$.ajax(
	{
		type: "GET",
		url: "<? echo url('leaveMessage/MessageModify'); ?>",
		data: "messageId="+mid+"&act=status",
		success: function(data)
		{
			messageLoad();
		},
		error: function()
		{
			alert("ERROR OCCUR!");
		}
	});
	$("#cPanel"+mid).css("display","block");
}

<?
/*
 * event: show
 * 显示备注
 */
?>
function commentShow(msgId)
{
	$("#commentModify"+msgId).css("display","block");
/*
	$.ajax(
	{
		type: "GET",
		url: "<? echo url('leaveMessage/MessageModify'); ?>",
		data: "messageId="+mid+"&act=status",
		success: function(data)
		{
			messageLoad();
		},
		error: function()
		{
			alert("ERROR OCCUR!");
		}
	});
*/
}

<?
/*
 * event: hide
 * 隐藏评论
 */
?>
function commentHide(msgId)
{
	$("#commentModify"+msgId).css("display","none");
}

<?
/*
 * event: format time
 * 
 */
?>
function formatTime(publishTime)
{
	var intval,iMinutes,iHours,iDays;
	var nowTime = parseInt(new Date().getTime()/1000);
	interval = nowTime - publishTime;
	iDays = parseInt(interval/86400);
	iHours = parseInt(interval/3600);
	iMinutes = parseInt(interval/60);
	if(iDays>=7)
	{
		var result = new Date(publishTime*1000);
		var r2 = result.getFullYear()+"-"+(result.getMonth()+1)+"-"+result.getDate()+" "+result.getHours()+":"+result.getMinutes();
		document.write(r2);
	}else if(iDays>=3 && iDays<7)
	{
		//return iDays+"天前";
		document.write(iDays+"天前");
	}else if(iDays>=2 && iDays<3)
	{
		//return "前天";
		document.write("前天");
	}else if(iDays>=1 && iDays<2)
	{
		//return "昨天";
		document.write("昨天");
	}else if(iDays<=0 && iHours>0)
	{
		//return iHours+"小时前";
		document.write(iHours+"小时前");
	}else if(iHours<=0 && iMinutes>0)
	{
		//return iMinutes+"分钟前";
		document.write(iMinutes+"分钟前");
	}else
	{
		//return "刚才";
		document.write("刚才");
	}
}